package com.own.stu.app.user.controller;


import com.own.stu.app.user.dto.ActionResult;
import com.own.stu.app.user.dto.PageListVO;
import com.own.stu.app.user.model.User;
import com.own.stu.app.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * user 前端控制器
 * </p>
 *
 * @author cl
 * @since 2024-01-21
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @ResponseBody
    @GetMapping("/byId/{id}")
    public User getBy(@PathVariable("id") String id) {
        return userService.getById(id);
    }

    @ResponseBody
    @GetMapping("/getList")
    public ActionResult getList() {
        List<User> realList = userService.list();
        PageListVO vo = new PageListVO();
        vo.setList(realList);
        return ActionResult.success(vo);
    }

    @RequestMapping("/update")
    @ResponseBody
    public User update() {
        User user = userService.getById(1);

        User newUser = new User();
        newUser.setId(user.getId());
        newUser.setCompany("AOLE1");
        System.out.println(" ======= ");
        userService.updateById(newUser);

        return user;
    }
}
